package com.lt.flashcard.bind;

import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.WrongValueException;
import org.zkoss.zul.Constraint;
import org.zkoss.zul.impl.InputElement;

public class EqualConstraint implements Constraint {
	
	private String targetName = "";
	
	public EqualConstraint(String targetName) {
		this.targetName = targetName;
	}
	
	public void validate(Component comp, Object value) throws WrongValueException {
		if(comp instanceof InputElement) {
			InputElement elm = (InputElement) comp;
			Object curVal = elm.getRawValue();
			if(value != null && !value.equals(curVal))
				throw new WrongValueException(comp, "Mật khẩu không trùng nhau");
		}
	}

	public String getTargetName() {
		return targetName;
	}

	public void setTargetName(String targetName) {
		this.targetName = targetName;
	}
}
